//
//  PasswordViewController.m
//  Browser
//
//  Created by eric on 10/26/14.
//  Copyright (c) 2014 eric. All rights reserved.
//

#import "PasswordViewController.h"
#import "AppDelegate.h"
@interface PasswordViewController ()

@end

@implementation PasswordViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    self.txtPassword = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 500, 50)];
    [self.txtPassword setBorderStyle:UITextBorderStyleRoundedRect];
    self.txtPassword.secureTextEntry = YES;
    self.txtPassword.returnKeyType = UIReturnKeyDone;
    self.txtPassword.delegate = self;
    [self.view addSubview:self.txtPassword];
    
    self.btnOk = [[UIButton alloc] initWithFrame:CGRectMake(60, 110, 50, 50)];
    [self.btnOk setTitle:@"OK" forState:UIControlStateNormal];
    [self.btnOk setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:self.btnOk];
    [self.btnOk addTarget:self action:@selector(buttonOK:) forControlEvents:UIControlEventTouchUpInside];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) login
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    
    if( [self.txtPassword.text isEqualToString:@"qw"])
    {
        
        [appDelegate performSelector:@selector(showMainPage)];
    }
    self.txtPassword.text = @"";
}

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
    [self login];
    
    return YES;
}

- (IBAction) buttonOK:(id)sender
{
    [self login];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
